﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BLL;
using Utility;
using System.Collections.Generic;
using Model;

public partial class VehicleUI_Fuel_CashFuelMgr : System.Web.UI.Page
{
    private void FuncCheck()
    {
        string pages = "F2_7&F2_7_1&F2_7_2&F2_7_3";
        Hashtable fc = RightChecker.GetPageFuncHT(pages.Split('&'), (IList<Function>)Session["FcList"]);

        btn_Add.Visible = (bool)fc["F2_7_1"];
        btn_Delete.Visible = (bool)fc["F2_7_3"];

        if (!(bool)fc["F2_7_2"])
        {
            GridView1.Columns[9].Visible = false;
        }
    }

    CashFuelBLL gBLL = new CashFuelBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FuncCheck();

            Session["Where"] = " A.organID = " + Session["OrganID"].ToString();
            if (Session["FilterFrameNO"] != null)
            {
                Session["Where"] = " A.organID = " + Session["OrganID"].ToString() + " AND A.FrameNO = '" + Session["FilterFrameNO"].ToString() + "'";
            }
            BindGridView();
        }
    }

    ////绑定分页和GridView方法
    private void BindGridView()
    {
        DataSet ds = new CashFuelBLL().GetList(Session["Where"].ToString());
        //初始化分页数据源实例
        PagedDataSource pds = new PagedDataSource();
        //设置总行数
        AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
        //设置分页的数据源
        pds.DataSource = ds.Tables[0].DefaultView;
        //设置当前页
        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        //设置每页显示页数
        pds.PageSize = AspNetPager1.PageSize;
        //启用分页
        pds.AllowPaging = true;
        //设置GridView的数据源为分页数据源
        GridView1.DataSource = pds;
        //绑定GridView
        GridView1.DataBind();
    }

    protected void btn_Add_Click(object sender, EventArgs e)
    {

    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        string idList = string.Empty;
        foreach (GridViewRow dr in GridView1.Rows)
        {
            CheckBox chk = (CheckBox)dr.FindControl("chk");
            if (chk.Checked)
            {
                int _id = Convert.ToInt32((dr.Cells[1].Text));
                idList += _id + ",";
            }

        }
        if (idList.Length > 0)
        {
            idList = idList.TrimEnd(',');
            bool re = new CashFuelBLL().DeleteList(idList);
            if (re)
            {
                UtilityService.AlertAndRedirect(this.Page, "删除成功!", "CashFuelMgr.aspx");
            }
            else
            {
                UtilityService.Alert(this.Page, "删除失败!");
            }
        }
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        Session["Where"] = " A.organID = " + Session["OrganID"].ToString() + " AND B.VehicleID LIKE '%" + txt_Search.Text.Trim() + "%'";
        BindGridView();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindGridView();
    }
}
